import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:lottie/lottie.dart';


///通用加载本地图片
class AutoImage extends StatelessWidget {
  const AutoImage(
    this.name, {
    super.key,
    this.color,
    this.width,
    this.height,
    this.fit,
    this.alignment = Alignment.center,
    this.borderRadius,
    this.reverse,
    this.repeat,
  });

  final String name;
  final Color? color;
  final double? width;
  final double? height;
  final BoxFit? fit;
  final bool? repeat;
  final bool? reverse;
  final AlignmentGeometry alignment;

  final BorderRadius? borderRadius;

  @override
  Widget build(BuildContext context) {
    if (name.toLowerCase().endsWith(".svg")) {
      return SvgPicture.asset(
        name,
        colorFilter: color != null ? ColorFilter.mode(color!, BlendMode.srcIn) : null,
        width: width,
        height: height ?? width,
        fit: fit ?? BoxFit.fitWidth,
        alignment: alignment,
        key: key,
      );
    } else if (name.toLowerCase().endsWith(".json")) {
      return Lottie.asset(
        name,
        width: width,
        height: height ?? width,
        fit: fit ?? BoxFit.fitWidth,
        alignment: alignment,
        key: key,
        reverse: reverse,
        repeat: repeat,
      );
    } else {
      return Image.asset(
        name,
        width: width,
        height: height ?? width,
        fit: fit ?? BoxFit.fitWidth,
        gaplessPlayback: true,
        alignment: alignment,
        color: color,
        key: key,
      );
    }
  }
}
